package com.my.chapter11;

import java.util.ArrayList;
import java.util.Map;

public class practice26 {
    static String[] reduction(Map<String, ArrayList<Integer>> map){
        int size = map.size();
        String[] words = new String[size];
        for(String word:map.keySet()){
            ArrayList<Integer> al= map.get(word);
            for(Integer i:al){
                words[i-1] = word;
            }
        }
        return words;
    }

    public static void main(String[] args) {
        String s = "A contented mind is the greatest blessing a man can enjoy in this world";
        String[] str = s.split(" ");
        for(String word:str){
            practice25.countWord(word);
        }
        Map<String, ArrayList<Integer>> map = practice25.map;
        String[] words = reduction(map);
        StringBuffer sb = new StringBuffer();
        for(int i = 0; i < words.length; i++){
            sb. append(words[i] + " ");
        }
        System.out.println(sb.toString());
    }
}
